package Arrays;

/**
 * 作者:hfj
 * 功能:141.环形链表
 * 日期: 2025/10/27 16:46
 */
public class HasCycle {

    //设置快慢指针
    public boolean hasCycle(ListNode head) {
        ListNode fast = head;
        ListNode slow = head;

        while (fast != null && fast.next != null){
            slow = slow.next;
            fast = fast.next.next;
            if (slow == fast){//如果两个指针相遇，则代表有环，否则无环
                return true;
            }
        }
        return false;
    }
}
